﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AUV5.Model;


namespace AUV5.Common
{
    public class OrderHelper
    {
        //      <div class="popinfo correctinfo">
        //    <p>你需要在截止日期<asp:Label ID="lblOrderEndTime" runat="server" Text=""></asp:Label>之前将你的服务完成并发出以获得报酬</p>
        //    <p class="ordermagtime">2011/11/30 10:10:30</p>
        //</div>

        //<div class="popinfo errorinfor">
        //    <p>已取消的订单信息：买家已强制取消此订单</p>
        //    <p class="ordermagtime">2011/11/30 10:10:30</p>
        //</div>

        //<div class="popinfo warninginfo">
        //    <p>截止日期提醒：到截止时间还剩24小时，请尽快完成并发送你的服务</p>
        //    <p class="ordermagtime">2011/11/30 10:10:30</p>
        //</div>

        #region##订单系统提示

        public const string Seller_OrderEndTimeTip = "你需要在截止日期{0}之前将你的服务完成并发出以获得报酬";   //卖家截取时间提醒

        public const string Seller_LastHoursTip = "截止日期提醒：到截止时间还剩24小时，请尽快完成并发送你的服务";   //卖家最后24小时提醒

        public const string Seller_EndDateTip = "此订单已到期,对方能强制取消订单";   //卖家订单到期提示

        public const string Buyer_OrderEndTimeTip = "此订单预计最迟会在{0}之前发货";   //买家截取时间提醒

        public const string Buyer_LastHoursTip = "截止日期提醒：离预计最迟发货时间还剩24小时";   //卖家最后24小时提醒

        public const string Buyer_EndDateTip = "此订单已到期,您可以强制取消订单";   //卖家订单到期提示

        #endregion


        #region##订单状态提示

        public const string OrderStatus_Default = "买家下了订单";         //未付款

        public const string OrderStatus_Payment = "买家己付款";           //买家已付款

        public const string OrderStatus_Shipped = "卖家发货了";           //卖家已发货

        public const string OrderStatus_Completed = "买家已收货";        //已收货

        public const string OrderStatus_SysCompleted = "系统自动完成订单";  //系统自动完成订单

        public const string OrderStatus_HasEvaluation = "买家已评价";     //买家已评价

        public const string OrderStatus_HasMutualEvaluation = "卖家已评价";  //卖家已评价

        public const string OrderStatus_BuyerRequestClosed = "买家请求取消订单     <div name=\"divReqClose\"><a name=\"sellerAgree\">同意</a> <a name=\"sellerNotAgree\">不同意</a></div>";   //买家请求取消

        public const string OrderStatus_BuyerRequestClosed2 = "买家请求取消订订单，等待卖家确认";

        public const string OrderStatus_SellerRequestClosed = "卖家请求取消订单     <div name=\"divReqClose\"><a name=\"buyerAgree\">同意</a> <a name=\"buyerNotAgree\">不同意</a></div>";  //卖家请求取消

        public const string OrderStatus_SellerRequestClosed2 = "卖家请求取消订单，等待买家确认";

        public const string OrderStatus_BuyerRefusedToClosed = "买家拒绝取消订单";  //买家拒绝取消

        public const string OrderStatus_SellerRefusedToCloesd = "买家拒绝取消订单"; //卖家拒绝取消

        public const string OrderStatus_Cloesd = "交易关闭";   //交易关闭

        public const string OrderStatus_BuyerForceClosed = "买家强制取消订单";   //买家强制取消

        public const string OrderStatus_SellerForceClosed = "卖家强制取消订单";  //卖家强制取消

        #endregion

        #region##正常类型提示
        /// <summary>
        /// 正常类型提示
        /// 创建人：Wilson
        /// 创建时间：2011-12-1
        /// </summary>     
        /// <param name="tips">提示语句</param>
        /// <param name="endTime">截止时间</param>
        /// <param name="createTime">消息发送时间</param>
        /// <returns></returns>
        public static string GetCorrectTip(string tips, DateTime endTime, DateTime createTime)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<li>");
            sb.Append("<div class=\"o_promptinfobar o_correctinfo\">");
            sb.Append("<p>");
            sb.AppendFormat(tips, Convert.ToString(endTime));
            sb.Append("</p>");
            sb.Append("<p class=\"o_magtime\">");
            sb.Append(Convert.ToString(createTime));
            sb.Append("</p>");
            sb.Append("</div>");
            sb.Append("</li>");
            return sb.ToString();
        }
        #endregion

        #region##警告类型提示
        /// <summary>
        /// 警告类型提示
        /// 创建人：Wilson
        /// 创建时间：2011-12-5
        /// </summary>
        /// <param name="tips">提示语句</param>
        /// <param name="createTime">消息发送时间</param>
        /// <returns></returns>
        public static string GetWarningTip(string tips, DateTime createTime)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<li>");
            sb.Append("<div class=\"o_promptinfobar o_promptinfo\">");
            sb.Append("<p>");
            sb.Append(tips);
            sb.Append("</p>");
            sb.Append("<p class=\"o_magtime\">");
            sb.Append(Convert.ToString(createTime));
            sb.Append("</p>");
            sb.Append("</div>");
            sb.Append("</li>");
            return sb.ToString();
        }
        #endregion

        #region##错误类型提示
        /// <summary>
        /// 错误类型提示
        /// 创建人：Wilson
        /// 创建时间：2011-12-1
        /// </summary>
        /// <param name="tips">提示语句</param>
        /// <param name="createTime">消息发送时间</param>
        /// <returns></returns>
        public static string GetErrorTip(string tips, DateTime createTime)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<li>");
            sb.Append("<div class=\"o_promptinfobar o_errorinfo\">");
            sb.Append("<p>");
            sb.Append(tips);
            sb.Append("</p>");

            sb.Append("<p class=\"o_magtime\">");
            sb.Append(Convert.ToString(createTime));
            sb.Append("</p>");

            sb.Append("</div>");
            sb.Append("</li>");
            return sb.ToString();
        }
        #endregion

        #region##时间戳
        /// <summary>
        /// 得到时间戳
        /// 创建人：Wilson
        /// 创建时间：2011-12-4
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public static string GetTimeStamp(DateTime dt)
        {
            DateTime startDt = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(2011, 1, 1));  //时间戳起始时间 
            string timeStamp = dt.Subtract(startDt).Ticks.ToString();
            timeStamp = timeStamp.Substring(0, timeStamp.Length - 7);
            return timeStamp;
        }

        /// <summary>
        /// 还原时间戳
        /// 创建人：Wilson
        /// 创建时间：2011-12-4
        /// </summary>
        /// <param name="timestamp"></param>
        /// <returns></returns>
        public static DateTime RestoreTimeStamp(string timeStamp)
        {
            DateTime startDt = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(2011, 1, 1));  //时间戳起始时间
            long lStamp = long.Parse(timeStamp + "0000000");
            TimeSpan tsNow = new TimeSpan(lStamp);
            DateTime dtResult = startDt.Add(tsNow);
            return dtResult;
        }
        #endregion

    }
    public interface IOrderMessage
    {
        string Write();
        DateTime GetDate();
    }

    public class SystemTip : IOrderMessage
    {
        public SystemTip(TipType type, string content, DateTime date)
        {
            this.type = type;
            this.content = content;
            this.date = date;
        }
        private TipType type;
        private string content;
        private DateTime date;
        public enum TipType
        {
            Error = -1,
            Warning = 0,
            Success = 1
        }

        public string Write()
        {
            StringBuilder sb = new StringBuilder();
            string style = "";
            switch (type)
            {
                case TipType.Error:
                    style = "o_errorinfo";
                    break;
                case TipType.Warning:
                    style = "o_promptinfo";
                    break;

                case TipType.Success:
                    style = "o_correctinfo";
                    break;
                default:
                    throw new Exception("定义了未处理的消息类型");
            }
            sb.Append("<li>");
            sb.Append(string.Format("<div class=\"o_promptinfobar {0}\">", style));
            sb.Append("<p>");
            sb.Append(content);
            sb.Append("</p>");
            sb.Append("<p class=\"o_magtime\">");
            sb.Append(new PageBase().GetTimeSpan(date));
            sb.Append("</p>");
            sb.Append("</div>");
            sb.Append("</li>");

            return sb.ToString();
        }
        public DateTime GetDate()
        {
            return date;
        }
    }

    public class Evaluation : IOrderMessage
    {
        public Evaluation(FeedBack fb)
        {
            this.isGood = fb.IsGood;
            this.content = fb.Content;
            this.reply = fb.Reply;
            this.createDate = fb.CreateDate;
            this.replyDate = fb.UpdateDate;
        }

        private bool isGood;
        private string content;
        private string reply;

        private DateTime createDate;
        private DateTime replyDate;

        public string Write()
        {
            StringBuilder sb = new StringBuilder();
            //买家评价
            sb.Append("<li>");
            sb.Append("<div class=\"appraisalbar\">");
            sb.Append("<div class=\"appraisalcon\">");
            if (isGood)
            {
                sb.Append("<p class=\"apptxt appicong\">好评</p>");
            }
            else
            {
                sb.Append("<p class=\"apptxt appiconb\">差评</p>");
            }
            sb.Append("<p class=\"appinfo\">");
            sb.Append(content);
            sb.Append("</p>");
            sb.Append("<div class=\"apptime\">");
            sb.Append(new PageBase().GetTimeSpan(createDate));
            sb.Append("</div></div>");
            //卖家回复
            if (!string.IsNullOrEmpty(reply))
            {
                sb.Append("<div class=\"appreply\"><p class=\"appreplyicon\"><img src=\"/!images/icon_top.jpg\" /></p>");
                sb.Append("<div class=\"appreplyinfo\"><p><span>回复：</span>");
                sb.Append(reply);
                sb.Append("</p><p class=\"ordermagtime\">");
                sb.Append(new PageBase().GetTimeSpan(replyDate));
                sb.Append("</p></div></div>");
            }
            sb.Append("</div>");
            sb.Append("</li>");

            return sb.ToString();
        }
        public DateTime GetDate()
        {
            return createDate;
        }
    }

    public class Dialog : IOrderMessage
    {
        public Dialog(bool isSender, string senderPhotoPath, string content, DateTime date)
        {
            this.isSender = isSender;
            this.senderPhotoPath = senderPhotoPath;
            this.content = content;
            this.date = date;
        } 
        private bool isSender;
        private string senderPhotoPath;
        private string content;
        private DateTime date;

        public string Write()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("<li>");
            sb.Append("<p class=\"dialogavarat\">");
            sb.AppendFormat("<img src=\"{0}\" />", senderPhotoPath);
            sb.Append("</p>");

            if (isSender)
            {
                sb.Append("<p class=\"icongrey dialogicon\"></p>");
                sb.Append(" <div class=\"ordermaginfo mar_left massageinfogreybg\">");
            }
            else
            {
                sb.Append("<p class=\"iconblue dialogicon\"></p>");
                sb.Append("<div class=\"ordermaginfo mar_left massageinfobluebg\">");
            }

            sb.Append("<p>");
            sb.Append(content);
            sb.Append("</p>");
            sb.Append("<p class=\"ordermagtime\">");
            sb.Append(new PageBase().GetTimeSpan(date));
            sb.Append("</p>");
            sb.Append("</div>");
            sb.Append("</li>");

            return sb.ToString();
        }
        public DateTime GetDate()
        {
            return date;
        }
    }
}
